<?php
//网络教研平台数据抓取
class up_data extends control
{
	public function __construct()
	{
		header("Content-Type: text/html; charset=utf-8");
		set_time_limit(0);//设置不超时.		
		parent::__construct();
		
		$this->apcdservice = 'http://218.28.143.166:82/apcdservice/';		//客户端数据请求地址头
		$this->rone = 'http://218.28.88.82/rone/';							//网站登录地址头
		$this->apcd = 'http://218.28.88.82/apcd/';							//网站数据地址头
		$this->regieapp_case = 'http://218.28.88.82/regieapp_case/';							//网站数据地址头
		$this->regieapp_lic = 'http://218.28.88.82/regieapp_lic/';  //证件请求头
		
		/* $this->roneurl = 'http://10.3.65.16/';
		$this->apcdservice = 'http://218.28.143.166:82/apcdservice/';		//客户端数据请求地址头
		$this->rone = $this->roneurl.'rone/';							//网站登录地址头
		$this->apcd = $this->roneurl.'apcd/';							//网站数据地址头
		$this->regieapp_case = $this->roneurl.'regieapp_case/';							//网站数据地址头
		$this->regieapp_lic = $this->roneurl.'regieapp_lic/';  //证件请求头 */
	}
	
	//获取任务类型
	public function monthplan_findTaskTypeList(){
		$cookie_file = dirname(__FILE__).'/cookie.txt';

		/*********开始登陆获取token***********/
		$url = $this->rone.'login?userid=csny_lishany&sysId=4&linkpage=&userName=csny_lishany&j_username=csny_lishany&password=1&j_password=1';
		
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
		$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
		$m = parse_url($m[0][1]);
		$m = explode('=',$m['path']);
		$token = $m[1];
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		/**************获取任务类型***********/
		$url = $this->apcd.'plan/monthplan_findTaskTypeList.do?taskSource=908003&doflag=1';
		//初始化
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_COOKIE, $cookie);
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		$task_type = json_decode($output); 
				
	}
	
	//获取apcd商户
	public function insert_apcd_customer(){
		$cookie_file = dirname(__FILE__).'/cookie.txt';

		$user = $this->up_data->find_apcd_all_user();
		
		foreach($user as $v){
			$userid = $v->userid;
			$userName = $v->userName;
			$j_username = $v->userName;
			$password = $v->password;
			$j_password = $v->password;
			$sysId = 4;
		
			/*********开始登陆获取token***********/
			$url = $this->rone.'login?';
			$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";

			$ch = curl_init();
			//设置选项，包括URL
			curl_setopt($ch, CURLOPT_URL,$url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch,CURLOPT_HEADER,1);
			curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
			preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
			$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
			$m = parse_url($m[0][1]);
			$m = explode('=',$m['path']);
			$token = $m[1];
			//执行并获取HTML文档内容
			$output = curl_exec($ch);
			//释放curl句柄
			curl_close($ch);
			
			//获取cookie
			$lurl = $this->apcd.'plan/monthplan_ui.do?result=login&ROLTPAToken='.$token;
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$lurl);
			curl_setopt($ch, CURLOPT_HEADER,0);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
			//curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			$response = curl_exec($ch);
			curl_close($ch); 
			
			//查询商户
			$post_data = array('userDeptCode'=>1041100321,'cityCode'=>10411001,'userStation'=>'sgy','page'=>1,'rows'=>1000);

			//添加商户池
			$dataurl = $this->apcd.'plan/monthplan_findCustomerList.do';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
			$response = curl_exec($ch);
			curl_close($ch); 
			//数据入库
			$this->up_data->insert_apcd_customer(json_decode($response));
		
		}
	}
	
	
	//抓取apcd所有商户		http://localhost/get_data/pds/up_data-find_first_sq
	public function find_first_sq(){
		
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$userid = 'xc_zhangyx';
		$userName = 'xc_zhangyx';
		$j_username = 'xc_zhangyx';
		$password = 'sty123';
		$j_password = 'sty123';
		$sysId = 4;
	
		//初始申请
		$customerStatus_array = array('2701');
			
		$this->up_data->push_div_content('.scorpall','开始同步商户数据.............................................<br />');
		foreach($customerStatus_array as $customerStatus){
			for($p = 1; $p<=10000; $p ++){
							
				//查询商户列表
				$post_data = array(
					'address'=>'',
					'cityCode'=>'10410401',
					'clientName'=>'',
					'countryCode'=>'',
					'customerStatus'=> $customerStatus,
					'gridLevel'=>1,
					'gridName'=>'10410401',	
					'lisenceNo'=>'',
					'page'=>$p,
					'rows'=>100,
					'status'=>'',
					'tel'=>''
				);

				$dataurl = $this->apcd.'baseinfo/customerManage_findCustomerManageList.do';
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$dataurl);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($ch, CURLOPT_POST,1);
				curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
				curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
				//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
				$customerlist = curl_exec($ch);
				curl_close($ch);
				//a($customerlist);exit;
				$customerlist = json_decode($customerlist);
				$customerlist = $customerlist->rows;
				
				if(!$customerlist){
					break;
				}
				foreach($customerlist as $k => $cv){
					
					$licenseNo = $cv->LICENSE_NO;
					$clientCode = $cv->CLIENT_CODE;
					$sgy_user_name = @$cv->SGY_USER_NAME;
					
					$lurl = $this->apcd.'baseinfo/customerManage_initLicenseInfoUI.do?licenseNo='.$licenseNo.'&clientCode='.$clientCode.'&ifQuery=';
					
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL,$lurl);
					curl_setopt($ch, CURLOPT_HEADER,0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
					curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
					$licenseinfo = curl_exec($ch);
					curl_close($ch); 
					
					//许可证信息
					$customer = $this->up_data->extract_data($licenseinfo);
					
					$lurl = $this->apcd.'baseinfo/customerManage_initMarketInfoUI.do?licenseNo='.$licenseNo.'&clientCode='.$clientCode.'&ifQuery=';
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL,$lurl);
					curl_setopt($ch, CURLOPT_HEADER,0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
					curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
					$Marketinginformation = curl_exec($ch);
					curl_close($ch); 
					
					//获取营销信息
					$Marketinginformation = $this->up_data->Marketinginformation($Marketinginformation);
					
					
					//市场监管信息
					$lurl = $this->apcd.'baseinfo/customerManage_initMarketSurveillanceUI.do?licenseNo='.$licenseNo.'&clientCode='.$clientCode.'&ifQuery=&countryCode=&ifGrid=';
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL,$lurl);
					curl_setopt($ch, CURLOPT_HEADER,0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
					curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
					$marketregulatory = curl_exec($ch);
					curl_close($ch); 
					
					//获取营销信息
					$marketregulatory = $this->up_data->marketregulatory($marketregulatory);

					//合并数据
					$customer = array_merge($customer,$Marketinginformation,$marketregulatory);
					//a($customer);exit;
					$this->up_data->import_customer($customer,$customerStatus,$sgy_user_name);

				}
				
			}
		}
		
		$this->up_data->push_div_content('.scorpall','处理中，请稍等.............................................<br />');
		
		//更新缓存
		//$lurl = 'http://152.136.43.124:8088/initSTYBussiness';
		$lurl = 'http://152.136.43.124:8088/initSTYBussiness2';
		$gop = array();
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$gop);
		curl_setopt($ch, CURLOPT_TIMEOUT, 180);  
		$gores = curl_exec($ch);
		curl_close($ch);
		
		//echo $gores;
		
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';exit;
	}
	
	//真假烟数据		http://localhost/get_data/pds/up_data-tfcigdata
	public function tfcigdata(){
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		$dataquery = 'http://10.3.65.16/dataquery';
		$dataquery_url = $dataquery.'/statistics/cs_getTrueStatisticsList.do';
		
		
		$qryBD = '2020-07-01';
		$qryED = '2020-07-30';
		$refBD = '2020-06';
		
		$qryBD = date('Y-m-01',strtotime('-1 month'));
		$qryED = date('Y-m-d',strtotime(date('Y-m-01').' -1 day'));
		$refBD = date('Y-m');
		
		$flag = array(1,2);
		
		foreach($flag as $fv){
			$post_data = array();
			$post_data['flag'] = $fv;
			$post_data['his'] = 1;
			$post_data['orgLevel'] = 2;
			$post_data['unitCode'] = '10410401';
			$post_data['showType'] = 2;
			$post_data['qryBD'] = $qryBD;
			$post_data['qryED'] = $qryED;
			$post_data['isRef'] = 0;
			$post_data['refBD'] = $refBD;
			$post_data['refED'] = $refBD;

			//市场监管信息
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataquery_url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			$customerlist = curl_exec($ch);
			curl_close($ch);
			
			if($customerlist){
				$customerlist = json_decode($customerlist);
				if($customerlist->total != 0){
					foreach($customerlist->rows as $k => $v){
						if($v->ORG_NAME == '合计' or $v->ORG_NAME == '平顶山市局'){
							continue;
						}
						$durl = $dataquery.'/statistics/cs_getTrueStatisticsDetail2.do';
						$dpost = array();
						$dpost['flag'] = $fv;
						$dpost['his'] = 1;
						$dpost['orgLevel'] = 3;
						$dpost['unitCode'] = '';
						$dpost['showType'] = 2;
						$dpost['cityUuid'] = $v->CITY_UUID;
						$dpost['orgUuid'] = $v->ORG_UUID;
						$dpost['detailType'] = 'IS_CITY_OUT';
						$dpost['qryBD'] = $qryBD;
						$dpost['qryED'] = $qryED;
						$dpost['isRef'] = 0;
						$dpost['refBD'] = $refBD;
						$dpost['refED'] = $refBD;
						
						$ch = curl_init();
						curl_setopt($ch, CURLOPT_URL,$durl);
						curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
						curl_setopt($ch, CURLOPT_POST,1);
						curl_setopt($ch, CURLOPT_POSTFIELDS,$dpost);
						curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
						$details = curl_exec($ch);
						curl_close($ch);
						
						if($details){
							$details = json_decode($details);
							$this->up_data->insert_tfcig($qryBD,$qryED,$details->rows,$fv);
						}
						
					}
				}
			}
		}
		
		a($customerlist);
	}
	
	//抓取apcd所有商户		http://localhost/get_data/pds/up_data-find_all_apcd_customer
	public function find_all_apcd_customer(){
		
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
	
		$cookie_file = dirname(__FILE__).'/cookie.txt';
	
		/* $userid = 'xc_zhangyx';
		$userName = 'xc_zhangyx';
		$j_username = 'xc_zhangyx';
		$password = 'sty123';
		$j_password = 'sty123';
		$sysId = 4; */
		
		$customer = $this->up_data->get_zcustomer();
		//a($customer);exit;
		
		
		//营业状态
		$customerStatus_array = array(2701,2702,2703,2704,2705,2706,2707);			
		//$customerStatus_array = array(2705);			
			
		$this->up_data->push_div_content('.scorpall','开始同步商户数据.............................................<br />');
		
		
		//foreach($customerStatus_array as $customerStatus){
		//foreach($customer as $cus){
			for($p = 1; $p<=500; $p ++){
				$this->up_data->push_div_content('.scorpall',$p.'.............................................<br />');
				//$customerStatus = '2702';//抓取正常经营的
			
				//查询商户列表
				$post_data = array(
					'address'=>'',
					'cityCode'=>'10410401',
					'clientName'=>'',
					'shopName'=>'',
					'clientLevel'=>'',
					'countryCode'=>'',
					'customerStatus'=> '2701,2702,2703,2704,2705,2706,2707',
					'gridLevel'=>1,
					'gridName'=>'10410401',	
					//'lisenceNo'=>$cus->license,
					'lisenceNo'=>'',
					'page'=>$p,
					'rows'=>50,
					'status'=>'',
					'tel'=>''
				);
				
				//a($post_data);
				$dataurl = $this->apcd.'baseinfo/customerManage_findCustomerManageList.do';
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$dataurl);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($ch, CURLOPT_POST,1);
				curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
				curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
				//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
				$customerlist = curl_exec($ch);
				curl_close($ch);
				//a($customerlist);exit;
				$customerlist = json_decode($customerlist);
				$customerlist = $customerlist->rows;
				
				if(!$customerlist){
					break;
				}
				foreach($customerlist as $k => $cv){
					
					/* if($k != 0){
						if($cv->GRID_NAME == '未归入网格'){
							continue;
						}
					} */
					
					
					$licenseNo = $cv->LICENSE_NO;
					$customerStatus = $cv->NOW_EFFECT_STATUS;
					
					//$licenseNo = '410425104953';
					$clientCode = $cv->CLIENT_CODE;
					$sgy_user_name = @$cv->SGY_USER_NAME;
					/* $clientCode = '411002103929';
					$licenseNo = '411002103929';  */
					$lurl = $this->apcd.'baseinfo/customerManage_initLicenseInfoUI.do?licenseNo='.$licenseNo.'&clientCode='.$clientCode.'&ifQuery=';
					
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL,$lurl);
					curl_setopt($ch, CURLOPT_HEADER,0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
					curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
					$licenseinfo = curl_exec($ch);
					curl_close($ch); 
					
					//许可证信息
					$customer = $this->up_data->extract_data($licenseinfo);
					
					$lurl = $this->apcd.'baseinfo/customerManage_initMarketInfoUI.do?licenseNo='.$licenseNo.'&clientCode='.$clientCode.'&ifQuery=';
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL,$lurl);
					curl_setopt($ch, CURLOPT_HEADER,0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
					curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
					$Marketinginformation = curl_exec($ch);
					curl_close($ch); 
					
					//获取营销信息
					$Marketinginformation = $this->up_data->Marketinginformation($Marketinginformation);
					
					
					//市场监管信息
					$lurl = $this->apcd.'baseinfo/customerManage_initMarketSurveillanceUI.do?licenseNo='.$licenseNo.'&clientCode='.$clientCode.'&ifQuery=&countryCode=&ifGrid=';
					$ch = curl_init();
					curl_setopt($ch, CURLOPT_URL,$lurl);
					curl_setopt($ch, CURLOPT_HEADER,0);
					curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
					curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
					$marketregulatory = curl_exec($ch);
					curl_close($ch); 
					
					//获取营销信息
					$marketregulatory = $this->up_data->marketregulatory($marketregulatory);

					//合并数据
					$customer = array_merge($customer,$Marketinginformation,$marketregulatory);
					//a($customer);exit;
					$this->up_data->import_customer($customer,$customerStatus,$sgy_user_name,$cv);

				}
				
			}
		//}
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';exit;
	}
	
	//	http://localhost/get_data/pds/up_data-grab_faith_level222
	public function grab_faith_level222(){
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$month = '2020-06';
		$LTPAToken = 'cGRzX3hpYXlnKjhhODNjMTkxNjJlMTA2YWMwMTYyZjU0NmJkNDYwMDEwKjIqUjFGcmFtZXdvcms0LjAqMTU5NDY0MzcwNDEyOQ==';
		
		$fath_url = 'http://10.64.2.71:8881/data/integrity/customer/licenseinfo';
		
		$url = $fath_url.'/list?result=login&LTPAToken='.$LTPAToken;
        
		// 上次执行到2351
		for($p=64;$p<1000;$p++){
			$post_data = array();
			$post_data['page'] = $p;
			$post_data['limit'] = '100';
			$post_data['orgUuid'] = '014114';
			$post_data['lawsLevelCode'] = '';
			$post_data['promiseLevelCode'] = '';
			$post_data['month'] = $month;
			$post_data['licenseNo'] = '';
			$post_data['managerName'] = '';
			$post_data['nowEffectStatus'] = '';
			$post_data['entName'] = '';
			$post_data['address'] = '';
			$post_data['targetCode'] = '';
			$post_data['orgCode'] = '10410401';
			
			$arr = array();
			$resdata = $this->http_request_post_no_cookie($url,$post_data);
			//a($resdata);exit;
			if($resdata){
				$resdata = json_decode($resdata);
				
				if($resdata->data){
					$details_url = $fath_url.'/queryCustomerLevelTarget?result=login&LTPAToken='.$LTPAToken;
					$data = $resdata->data;
					
					foreach($data as $v){
						$license = $v->licenseNo;					
						$faith_level = $v->lawsLevelName.$v->promiseLevelName;		
						$laws_level = $v->lawsLevelName;
						$laws_score = $v->lawsLevelScore;
						$promise_level = $v->promiseLevelName;
						$promise_score = $v->promiseLevelScore;
						
						$this->up_data->push_div_content('.scorpall',$license.'.............................................<br />');
						// 更新诚信等级
						$this->up_data->update_fath_level($license,$faith_level,$laws_level,$laws_score,$promise_level,$promise_score);
						
						$dp = array();
						$dp['page'] = '1';
						$dp['limit'] = '100';
						$dp['clientCode'] = $v->clientCode;
						$dp['month'] = $month;
						
						$details_data = $this->http_request_post_no_cookie($details_url,$dp);
						if($details_data){
							$details_data = json_decode($details_data);
							
							if(isset($details_data->data->promiseList)){
								$type = 1;
								$details = $details_data->data->promiseList;
								$this->up_data->insert_fath_level_details($license,$month,$type,$details);
							}
							
							if(isset($details_data->data->lawList)){
								$type = 2;
								$details = $details_data->data->lawList;
								$this->up_data->insert_fath_level_details($license,$month,$type,$details);
							}
							
							
						}
					}
				}else{
					echo '<span style="color:red;font-size:26px;"> 同步完成</span>';exit;
				}
				
			}else{
				echo '<span style="color:red;font-size:26px;"> 同步完成</span>';exit;
			}
		}
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';exit;
	}
	
	
	//查询县信息     http://localhost/get_data/pds/up_data-get_cases
	public function get_cases(){
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		
		$url = $this->regieapp_case. "ttmorgbaseinfo/getTree?ifAll=1&tarEnt=8a83c1905591d8e9015591f973ee0012&orgType=undefined&ifParentCheck=&onlyUnit=&isSquadron=undefined";
        
		$post_data = array();
		$post_data['ifAll'] = 1;
		$post_data['tarEnt'] = '8a83c1905591d8e9015591f973ee0012';
		$post_data['orgType'] = 'undefined';
		$post_data['ifParentCheck'] = '';
		$post_data['onlyUnit'] = '';
		$post_data['isSquadron'] = 'undefined';
		
		$arr = array();
		$resdata = $this->http_request_post($url,$post_data);
		
		if($resdata){
			$resdata = json_decode($resdata);
			
			foreach($resdata as $v){
				if($v->pId == '014114' && $v->nocheck == 1){
					$arr[] = $v;
				}
			}
			

		}
		//a($arr);exit;
		
		if(!empty($arr)){
			$handleProc = array(1,2,3);		//案件类型
			
			//foreach($arr as $ca){
				//$_SESSION['orgCode'] = $ca->id;        //三统一机构id
				
				//foreach($handleProc as $handleProc_v){
					//$_SESSION['handleProc'] = $handleProc_v;
					
					//$this->processing();        //在办案件抓取
					
					$this->end_list();          //办结案件抓取
				//}
			//}
		}
		
		//($arr);exit;

        
	}
	
	//在办案件查询    http://218.28.88.82/get_data/nycase-processing
	public function processing(){
	    //$this->login();		//登录
	   
	    $list_post = array();
		$list_post['tCCaseinfoSon.orgShortname'] = '平顶山市烟草专卖局';
		//$list_post['seqCode'] = $_SESSION['orgCode'];
		$list_post['seqCode'] = '014114';
		$list_post['caseState'] = 0;
		//$list_post['handleProc'] = $_SESSION['handleProc'];
		//$list_post['regStartTime'] = '';
		//$list_post['regEndTime'] = '';
		$list_post['_search'] = false;
		$list_post['pageSize'] = '1000';
		$list_post['pageNo'] = '1';
		$list_post['orderFields'] = 'caseDate';
		$list_post['order'] = 'desc';
		$list_post['nd'] = '1593572736740';
		//$list_post['party'] = '张丰丽';
		
       // $unitCode = substr($_SESSION['orgCode'],0,strlen($_SESSION['orgCode'])-2);  //截取单位编码
		$processing_post = array();
		$processing_post['handleStatus'] = 1;            //办理状态
		$processing_post['unitCode'] = '014114';                //014121
		$processing_post['orgRank'] = '3';    
		
		$processing_perm = http_build_query($processing_post);

		$list_url = $this->regieapp_case.'casequery/caseInfoList?'.$processing_perm;
		$list_res = $this->http_request_post($list_url,$list_post);
		//$list_res = $this->p->curl($list_url,'POST',$list_post,false,1);
		$list_data = json_decode($list_res);		//电子卷宗列表数据
        //a($list_res);exit;
        
		for($page = 1;$page <= $list_data->total;$page++){
			$this->up_data->push_div_content('.scorpall',$page.'.............................................<br />');
			$res = $this->data_grab_processing($list_post,$list_url,$page);
			
			if(!$res){
			    $page--;
			}
		}
		
	}
	
	
	//办结案件查询    http://218.28.88.82/get_data/nycase-processing
	public function end_list(){
	    //$this->login();		//登录
	   
	    $list_post = array();
		$list_post['tCCaseinfoSon.orgShortname'] = '平顶山市烟草专卖局';
		$list_post['seqCode'] = '014114';
		//$list_post['seqCode'] = $_SESSION['orgCode'];
		//$list_post['caseState'] = '';
		//$list_post['handleProc'] = $_SESSION['handleProc'];

		$list_post['_search'] = false;
		$list_post['pageSize'] = '100';
		$list_post['pageNo'] = '1';
		$list_post['orderFields'] = 'caseDate';
		$list_post['order'] = 'desc';
		$list_post['nd'] = '1592966913577';
		//$list_post['party'] = '张丰丽';
		
        //$unitCode = substr($_SESSION['orgCode'],0,strlen($_SESSION['orgCode'])-2);  //截取单位编码
		$processing_post = array();
		$processing_post['handleStatus'] = 9;            //办理状态
		$processing_post['unitCode'] = '014114';                //014121
		$processing_post['orgRank'] = '3';    
		
		$processing_perm = http_build_query($processing_post);
		
		$list_url = $this->regieapp_case.'casequery/caseInfoList?'.$processing_perm;
		
		$list_res = $this->http_request_post($list_url,$list_post);
		//$list_res = $this->p->curl($list_url,'POST',$list_post,false,1);
		$list_data = json_decode($list_res);		//电子卷宗列表数据
        //a($list_data);exit;
		for($page = 1;$page <= $list_data->total;$page++){
			echo '--------------------------------'.$page.'<br />';
			$res = $this->data_grab_processing($list_post,$list_url,$page);
			
			if(!$res){
			    $page--;
			}
		}
		
	}
	
	
	//案件详情数据抓取
	public function data_grab_processing($list_post,$list_url,$page){
	    
	    $list_post['pageNo'] = $page;
	    
		$list_res = $this->http_request_post($list_url,$list_post);
	    //$list_res = $this->p->curl($list_url,'POST',$list_post,false,1);
		$list_data = json_decode($list_res);		//电子卷宗列表数据
		//a($list_data);exit;
		if(isset($list_data->rows)){
		    $list_data = $list_data->rows;
		}else{
		    return false;
		}
		
		
		foreach($list_data as $v){
			$caseUuid = $v->caseUuid;
			
			//$cainfo = $this->nycase->if_exeit_case($caseUuid);
			
			//if($cainfo){
			//	continue;
			//}
			
			//基础信息
			$this->base_info($caseUuid);
			
			//询问笔录数据抓取
			//$this->tCDocAskRecord($caseUuid);
			
			//涉案人员
		    $this->suspect_info($caseUuid);
			
			//车辆信息
			$this->car_info($caseUuid);
			
			//卷烟信息
			$this->cigarette_info($caseUuid);
		}
		
		return true;
	}
	
		
	//基础信息
	public function base_info($caseUuid){
			
		//基础信息
		$base_post = array();
		$base_post['caseUuid'] = $caseUuid;
		$base_post['type'] = '0';
		
		$perm_base = http_build_query($base_post);
		
		$base_url = $this->regieapp_case.'casequery/getCaseDetail?'.$perm_base;
		$bnase_data= $this->http_request_post($base_url,$base_post);
		//$base_res = $this->p->curl($base_url,'POST',$base_post,false,1);
		$nase_data = @json_decode(@$bnase_data)->rows;	//基础数据
		//a($nase_data);exit;
		if($nase_data){
			$this->up_data->insert_base_info($nase_data);
		}
		
	}
	
	//涉案人员
	public function suspect_info($caseUuid){
		$suspect_post = array();
		$suspect_post['caseUuid'] = $caseUuid;
		$suspect_post['type'] = 3;
		$suspect_post['idCard'] = '';
		
		$perm_suspect = http_build_query($suspect_post);
		$suspect_url = $this->regieapp_case.'casequery/getCaseDetail?'.$perm_suspect;
		
		//$snase_data= $this->http_request_post($sbase_url,$sbase_post);
		//$suspect_res = $this->p->curl($suspect_url,'POST',$suspect_post,false,1);	//笔录页面
		$suspect_res = $this->http_request_post($suspect_url,$suspect_post);	
		$suspect_data = @json_decode($suspect_res)->rows;
		
		if($suspect_data){
			$this->up_data->insert_suspect_info($suspect_data);
		}
		
	}
	
	//车辆信息
	public function car_info($caseUuid){
		
		$car_post = array();
		$car_post['caseUuid'] = $caseUuid;
		$car_post['type'] = 5;
		$perm_car = http_build_query($car_post);
		$car_url = $this->regieapp_case.'casequery/getCaseDetail?'.$perm_car;
		$ccar_data= $this->http_request_post($car_url,$car_post);
		//$car_res = $this->p->curl($car_url,'POST',$car_post,false,1);	//笔录页面
		$car_data = json_decode($ccar_data)->rows;
		
		//车辆信息入库
		if($car_data){
			$this->up_data ->insert_case_car($car_data,$caseUuid);
		}
	}
	
		
	//卷烟信息
	public function cigarette_info($caseUuid){
		$cigarette_post = array();
		$cigarette_post['caseUuid'] = $caseUuid;
		$cigarette_post['type'] = 4;
		
		$cigarette_suspect = http_build_query($cigarette_post);
		$cigarette_url = $this->regieapp_case.'casequery/getCaseDetail?'.$cigarette_suspect;
		
		$cigarette_res = $this->http_request_post($cigarette_url,$cigarette_post);
		//$cigarette_res = $this->p->curl($cigarette_url,'POST',$cigarette_post,false,1);	//笔录页面
		$cigarette_data = json_decode($cigarette_res)->rows;
	    
		if($cigarette_data){
			$this->up_data->insert_cigarette_info($cigarette_data);
		}
		
	}
		
	//http请求
	public function http_request_get($lurl){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_HEADER,0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		$res = curl_exec($ch);
		curl_close($ch); 
		
		return $res;
	}
	
	//http请求POST
	public function http_request_post($lurl,$post_data){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		$res = curl_exec($ch);
		curl_close($ch);
		
		return $res;
	}
	
		//http请求POST
	public function http_request_post_no_cookie($lurl,$post_data){
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		$res = curl_exec($ch);
		curl_close($ch);
		
		return $res;
	}
	
	//更新网格数据
	public function update_sty_user(){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$userid = 'xc_zhangyx';
		$userName = 'xc_zhangyx';
		$j_username = 'xc_zhangyx';
		$password = 'sty123';
		$j_password = 'sty123';
		$sysId = 4;
	
		/*********开始登陆获取token***********/
		$url = $this->rone.'login?';
		$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";


		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
		$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
		$m = parse_url($m[0][1]);
		$m = explode('=',$m['path']);
		$token = $m[1];
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		//获取三级网格
		$post_data = array();
		$dataurl = $this->apcd.'check/clientMap_getOwnerGridTree.do';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$dataurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		$gride_3 = curl_exec($ch);
		curl_close($ch);
		$gride_3 = json_decode($gride_3);
		$gride_3 = $gride_3[0]->children;
		//a($gride_3);exit;
		//三级网格入库
		$this->up_data->update_gride_3($gride_3);
		
		echo('中队》》三级网格同步完成》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
		ob_flush();
		flush();
		
		$j_data = array();
		foreach($gride_3 as $k => $gride_v){
			$gride_id = $gride_v->id;
			
			//获取四级网格
			$post_data = array('id'=>$gride_id);
			$dataurl = $this->apcd.'check/clientMap_getOwnerGridTree.do';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
			$gride_4 = curl_exec($ch);
			curl_close($ch);
			$gride_4 = json_decode($gride_4);
			
			//四级网格入库
			$this->up_data->update_gride_4($gride_4,$gride_id);
			
			foreach($gride_4 as $gride_4_v){
				$gride5_id = $gride_4_v->id;
				
				//获取四级网格
				$post_data = array('id'=>$gride5_id);
				$dataurl = $this->apcd.'check/clientMap_getOwnerGridTree.do';
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$dataurl);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($ch, CURLOPT_POST,1);
				curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
				curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
				//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
				$gride_5 = curl_exec($ch);
				curl_close($ch);
				$gride_5 = json_decode($gride_5);
								

				//五级网格入库
				$res = $this->up_data->update_gride_5($gride_5,$gride_id,$gride5_id);
				foreach($res as $jv){
					$j_data[] = $jv;
				}
			}
		}
		
		echo '更新完成';
		ob_flush();
		flush();
	}
	
	//更新客户营业状态
	public function updata_customer_operating(){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$userid = 'xc_hanwx';
		$userName = 'xc_hanwx';
		$j_username = 'xc_hanwx';
		$password = '123456';
		$j_password = '123456';
		$sysId = 4;
	
		/*********开始登陆获取token***********/
		$url = $this->rone.'login?';
		$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";


		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
		$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
		$m = parse_url($m[0][1]);
		$m = explode('=',$m['path']);
		$token = $m[1];
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		for($p = 1;$p<1000000000;$p++){
			$post_data = array(
				'_search'=>false,
				'areaType'=>3001,
				'nd'=>1495077215968,
				'nowEffectStatus'=>2702,
				'order'=>'desc',
				'orderFields'=>'createTime',
				'pageNo'=>$p,
				'pageSize'=>'100',
				'unitCode'=>'01412012',
				'validateStart_end'=>'',
				'validateStart_start'=>''
			);
				
			$dataurl = 'http://218.28.88.82/regieapp_lic/licquery/findLicQueryByPage';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
			$output = curl_exec($ch);
			curl_close($ch);
			$output = json_decode($output);
			
			if(!empty($output->rows)){
				$this->up_data->updata_customer_operating($output->rows);	
			}else{
				echo(date('更新完成...............................<br />'));
				ob_flush();
				flush();
				exit;
			}
				
		}
	}

	
	//更新商户部分数据
	public function updata_customer_Part_info(){
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$userid = 'xc_zhangyx';
		$userName = 'xc_zhangyx';
		$j_username = 'xc_zhangyx';
		$password = 'sty123';
		$j_password = 'sty123';
		$sysId = 4;
	
		/*********开始登陆获取token***********/
		$url = $this->rone.'login?';
		$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";
		
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';

		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
		$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
		$m = parse_url($m[0][1]);
		$m = explode('=',$m['path']);
		$token = $m[1];
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		//获取三级网格
		$post_data = array();
		$dataurl = $this->apcd.'check/clientMap_getOwnerGridTree.do';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$dataurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		$gride_3 = curl_exec($ch);
		curl_close($ch);
		$gride_3 = json_decode($gride_3);
		$gride_3 = $gride_3[0]->children;

		$j_data = array();
		foreach($gride_3 as $k => $gride_v){
			$gride_id = $gride_v->id;
			
			//获取四级网格
			$post_data = array('id'=>$gride_id);
			$dataurl = $this->apcd.'check/clientMap_getOwnerGridTree.do';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
			$gride_4 = curl_exec($ch);
			curl_close($ch);
			$gride_4 = json_decode($gride_4);
			
			foreach($gride_4 as $gride_4_v){
				$gride5_id = $gride_4_v->id;
				
				//获取四级网格
				$post_data = array('id'=>$gride5_id);
				$dataurl = $this->apcd.'check/clientMap_getOwnerGridTree.do';
				$ch = curl_init();
				curl_setopt($ch, CURLOPT_URL,$dataurl);
				curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
				curl_setopt($ch, CURLOPT_POST,1);
				curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
				curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
				//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
				$gride_5 = curl_exec($ch);
				curl_close($ch);
				$gride_5 = json_decode($gride_5);
								
				//五级网格入库
				$res = $this->up_data->update_gride_5($gride_5,$gride_id,$gride5_id);
				foreach($res as $jv){
					$j_data[] = $jv;
				}
			}
		}
		
		/* ob_get_contents();
		echo('开始同步商户数据.............................................<br />');
		ob_flush();
		flush(); */
		
		$this->up_data->push_div_content('.scorpall','开始同步商户数据.............................................<br />');
		
		foreach($j_data as $k => $vs){
			$gride = $vs['gride'];
			
			//营业状态
			$customerStatus = '';
			
			//查询商户列表
			$post_data = array(
				'address'=>'',
				'cityCode'=>'10411001',
				'clientName'=>'',
				'countryCode'=>'10411003',
				'customerStatus'=> $customerStatus,
				'gridLevel'=>5,
				'gridName'=>$gride,
				'lisenceNo'=>'',
				'page'=>1,
				'rows'=>1000000,
				'status'=>'1',
				'tel'=>''
			);
				

			$dataurl = $this->apcd.'baseinfo/customerManage_findCustomerManageList.do';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
			$customerlist = curl_exec($ch);
			curl_close($ch);
			$customerlist = json_decode($customerlist);
			$customerlist = $customerlist->rows;
			a($customerlist);exit;
			foreach($customerlist as $cv){
				$this->up_data->updata_customer_Part_info($cv,$vs);
				
				/* echo(date('H:i:s').$cv->SHOP_NAME.'.............................................<br />');
				ob_flush();
				flush(); */
				$content = date('H:i:s').$cv->SHOP_NAME.'.............................................<br />';
				$this->up_data->push_div_content('.scorpall',$content);
			}
			
		}
		
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
		
	}
	

	//获取网格名称
	public function find_grid_name_k(){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		//中队长账号
		$user = array('xc_xuyu','xc_zhangyanj','xc_qinzx','xc_chenaj','xc_jinyc','xc_wangkn','xc_zhaogj','xc_duzq');
		
		foreach($user as $value){
			$userid = $value;
			$userName = $value;
			$j_username = $value;
			
			$password = 'sty123';
			$j_password = 'sty123';
			$sysId = 4;
		
			/*********开始登陆获取token***********/
			$url = $this->rone.'login?';
			$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";

			$ch = curl_init();
			//设置选项，包括URL
			curl_setopt($ch, CURLOPT_URL,$url);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch,CURLOPT_HEADER,1);
			curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
			preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
			$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
			$m = parse_url($m[0][1]);
			$m = explode('=',$m['path']);
			$token = $m[1];
			//执行并获取HTML文档内容
			$output = curl_exec($ch);
			//释放curl句柄
			curl_close($ch);
			
			//获取三级网格
			$post_data = array('page'=>1,'rows'=>10000);

			$dataurl = $this->apcd.'baseinfo/fifthGrid_fifthGridList.do';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
			$gride_K = curl_exec($ch);
			curl_close($ch);
			$gride_K = json_decode($gride_K);
			$gride_K = $gride_K->rows;
			
			//更新网格名称K开头
			$this->up_data->update_grid_nameK($gride_K);
		}
		
	}
	
	
	/*************添加任务池任务*****************/
	public function up_data_j(){
		$licenseno = isset($_POST['licenseno'])?$_POST['licenseno']:'';
		$taskDesc = isset($_POST['taskDesc'])?$_POST['taskDesc']:'';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$user = $this->up_data->get_task_pool_user($licenseno);
		
		$userid = $user->userid;
		$userName = $user->userName;
		$j_username = $user->userName;
		$password = $user->password;
		$j_password = $user->password;
		
		$sysId = 4;

		$userDeptCode = $user->userDeptCode;				//用户部门编号
		$cityCode = $user->cityCode;					//城市id
		
		/*********开始登陆获取token***********/
		$url = $this->rone.'login?';
		$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";
		
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		//curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
		$cookie = urldecode($m[1][0].';'.$m[1][1]);					//拼接cookie
		$m = parse_url($m[0][1]);
		$m = explode('=',$m['path']);
		$token = urldecode($m[1]);
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		/*************添加任务池页面获取cookie**************/
		//获取cookie
		$lurl = 'http://218.28.88.82/apcd/plan/monthplan_ui.do?result=login&LTPAToken='.$token;
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$lurl);
		curl_setopt($ch, CURLOPT_HEADER,0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
		curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		//curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		$response = curl_exec($ch);
		curl_close($ch);
		//a($response);exit;
		
		$customer = $licenseno;
		//获取任务对应apcd商户
		$chooseCustomers = $this->up_data->find_apcd_task_customer($customer);
		
		//所选商户数组
		$post_data = array('userDeptCode'=>$userDeptCode,'chooseCustomers'=>$chooseCustomers);
		//添加商户池
		$dataurl = $this->apcd."plan/monthplan_addCustomer2TaskPool.do?";
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$dataurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		$response = curl_exec($ch);
		curl_close($ch);
		
		//获取商户池添加结果
		$post_data = array('cityCode'=>$cityCode,'userDeptCode'=>$userDeptCode);
		$dataurl = $this->apcd.'plan/monthplan_findAddTempTaskList.do';
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$dataurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		$response = curl_exec($ch);
		curl_close($ch);

		//任务详情
		$benDate = date('Y-m-d');
		$endDate = date('Y-m-d',time()+24*3600*30);
		
		//添加计划
		$post_data = array('taskSource'=>'908002','taskType'=>'907008','benDate'=>$benDate,'endDate'=>$endDate,'userDeptCode'=>$userDeptCode,'taskDesc'=>$taskDesc,'problemType'=>'');
		$dataurl = $this->apcd.'plan/monthplan_insertTempTask2Pool.do';
		
		$ch = curl_init($dataurl);
		//curl_setopt($ch, CURLOPT_HEADER, 0);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		$response = curl_exec($ch);
		curl_close($ch);
		
		//审核通过
		//$this->task_pool_info($userid);
		
		
	}

	//获取任务池所有任务
	public function find_all_task_pool(){
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$userid = 'xc_zhangyx';
		$userName = 'xc_zhangyx';
		$j_username = 'xc_zhangyx';
		$password = 'sty123';
		$j_password = 'sty123';
		$sysId = 4;
		
		$taskMonth = date('Y-m');
	
		/*********开始登陆获取token***********/
		$url = $this->rone.'login?';
		$url .= "userid=$userid&sysId=$sysId&linkpage=&userName=$userName&j_username=$j_username&password=$password&j_password=$j_password";

		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_HEADER,1);
		curl_setopt($ch, CURLOPT_COOKIEJAR,$cookie_file); 	//存储cookies
		preg_match_all('/^Set-Cookie: (.*?);/m',curl_exec($ch),$m);
		$cookie = $m[1][0].';'.$m[1][1];					//拼接cookie
		$m = parse_url($m[0][1]);
		$m = explode('=',$m['path']);
		$token = $m[1];
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		
		//获取三级网格
		$post_data = array('cityCode'=>'10411001',
		'clientName'=>'',
		'gridOwner'=>'1041100101001_3,1041100101002_3,1041100101003_3,1041100101004_3,1041100101005_3,1041100101006_3',
		'licenceNO'=>'',
		'page'=>1,
		'rows'=>10000000,
		'taskDesc'=>'',
		'taskMonth'=>$taskMonth,
		'taskSource'=>'',
		'taskStatus'=>'',
		'userDeptCode'=>1041100311,
		'userStation'=>'sgy');
		$dataurl = $this->apcd.'plan/monthplan_findMonthTaskList.do';
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$dataurl);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		$res = curl_exec($ch);
		curl_close($ch);
		$res = json_decode($res);
		
		//更新任务池
		$this->up_data->insert_apcd_task_pool($res->rows);
	}
	
	//获取检查结果
	public function get_exec_customer_info(){
		
		$user = $this->up_data->find_apcd_all_user();
		
		foreach($user as $value){
			//获取apcd用户id
			$userid = $value->apcd_app_userid;
			
			//获取网格数据
			$g_url = $this->apcdservice.'queryGridList.do?json={"userId":"'.$userid.'"}';
			$gride = $this->get_data($g_url);
			if(!$gride){
				continue;
			}
			$gride = json_decode($gride)->results;
			
			$gridCodes = '';
			foreach($gride as $v){
				$gridCodes .= $v->tagId.',';
			}
			$gridCodes = substr($gridCodes,0,strlen($gridCodes)-1);
					
			//查询检查信息
			$info_url = $this->apcdservice.'getTaskList.do?json={"gridCodes":"'.$gridCodes.'","planType":"B","userId":"'.$userid.'"}';
			$exec_customer = $this->get_data($info_url);
			$exec_customer = json_decode($exec_customer)->results;
			
			//检查商户结果字段修改
			$is_check = $this->up_data->updata_checked($exec_customer);
			
			//添加巡检信息
			$this->up_data->insert_patrol_info($exec_customer,$value);
			
			//获取排序后的检查结果
			//$sort_workItemDataList = $this->up_data->sort_workItemDataList($exec_customer);
			//a($exec_customer);exit;
		}
	}
	
	//获取apcd平台日志
	public function get_day_log(){
		$date = isset($_GET['date'])?$_GET['date']:date('Y-m-d');
		
		//获取apcd用户信息
		$user = $this->up_data->find_apcd_all_user();
		
		foreach($user as $v){
			$userId = $v->apcd_app_userid;		//apcd用户id
			$log_url = $this->apcdservice.'getWorkDiaryList.do?json={"startDate":"'.$date.'","endDate":"'.$date.'","planType":"B","type":1,"status":0,"userId":"'.$userId.'"}';
			$res = $this->get_data($log_url);
			$res = json_decode($res);
			//添加到数据库
			$this->up_data->insert_apcd_log_to_xcyc($res->results,$userId,$date);
			//a($res);
		}
		
	}

	//获取网格apcd数据
	public function get_data_gride(){
		
		$user = $this->up_data->find_apcd_all_user();
		
		foreach($user as $v){
			$userid = $v->apcd_app_userid;
			$url = $this->apcdservice.'queryGridList.do?json={"userId":"'.$userid.'"}';
			
			$gride = $this->get_data($url);
			$gride = json_decode($gride)->results;
			$this->up_data->get_data_gride($gride,$userid);
		}
	}
	
	//获取apcd网格商户
	public function get_gride_customer(){
		//先更新网格数据
		$this->get_data_gride();
		
		//获取所有apcd网格id
		$date = date('Y-m-d');
		$user_gride = $this->up_data->get_user_gride();
		
		foreach($user_gride as $v){
			$url = $this->apcdservice.'queryNormalOrUnlicenseCustomers.do?json={"gridCodes":"'.$v->tagId.'","startDate":"'.$date.'","page":1,"isHaveLicense":"0","userId":"'.$v->userid.'","pageSize":20000,"endDate":"'.$date.'","keyWord":""}';
			$gride_customer = $this->get_data($url);
			$gride_customer = json_decode($gride_customer)->results;
			$this->up_data->get_gride_customer($gride_customer,$v->userid,$v->gridcode);
		}
		
	}

	//apcd添加走访临售户提交审核通过
	public function get_visit_customer($task_info){
		
		
		//专卖证号查询商户
		$task_info = json_decode($task_info,true);
		
		$date = date('Y-m-d',$task_info['date']);								//日期
		$planType = 'B';		//计划类型
		$planId = '';			//计划id
		
		
		//获取apcd平台用户id
		//$user = $this->up_data->find_apcd_user($task_info);		
		$user = $this->up_data->find_apcd_user1($task_info);	
		
		foreach($user as $value){
			$executors = '';		//执行人id串	
			$executorNames = '';	//执行人名字
			$t_data = array();
			
			//apcd用户id
			$userid = $value->userid;
			$clientCode = $value->licenseCode;
			
			//审核人信息
			$url = $this->apcdservice.'queryApprovalList.do?json={"userId":"'.$userid.'"}';
			$audit = $this->get_data($url);
			$audit = json_decode($audit)->results;
			$appPerson = $audit[0]->approvalId;		//appPerson
			
			//执行人信息
			$zurl = $this->apcdservice.'queryExecutorList.do?json={"userId":"'.$userid.'"}';
			$zuser = $this->get_data($zurl);
			$zuser = json_decode($zuser)->results;
			foreach($zuser as $v){
				if($userid == $v->tagId){
					$executors .= $v->tagId.',';
					$executorNames .= $v->tagName.',';
				}
			}
			$executors = substr($executors,0,strlen($executors)-1);					//执行人id列表
			$executorNames = substr($executorNames,0,strlen($executorNames)-1);		//执行人姓名列表
			
			$t_data['executorNames'] = $executorNames;
			$t_data['executors'] = $executors;
			$t_data['appPerson'] = $appPerson;
			$t_data['planType'] = $planType;
			$t_data['planId'] = $planId;
			$t_data['userId'] = $userid;
			$t_data['startDate'] = $date;
			$t_data['endDate'] = $date;
			
			//任务商户
			$c_data = $this->up_data->select_t_customer($clientCode);
			
			
			
			/******************任务池商户*********************/
			//获取网格
			$url = $this->apcdservice.'queryGridList.do?json={"userId":"'.$userid.'"}';
			$grid = $this->get_data($url);
			if(!$grid){
				continue;
			}
			
			$grid = json_decode($grid);
			$gs = '';
			foreach($grid->results as $val){
				$gs .= $val->tagId.',';
			}
			$gs = substr($gs,0,strlen($gs)-1);
			$json = '{"gridCodes":"'.$gs.'","startDate":"'.$date.'","page":1,"isHaveLicense":"","taskSource":"","pageSize":100,"endDate":"'.$date.'","keyWord":""}';
			
			//获取任务池任务
			$url = $this->apcdservice.'queryTaskPoolCustomers.do?json='.$json;
			$list = $this->get_data($url);
			$list = json_decode($list);
			$list = $list->results;
			
			//获取已分配到日计划的任务池任务id
			$task_id = $this->up_data->get_task_pool_exec_customer($userid);
			$customerList = array();
			foreach($list as $v){
				if(in_array($v->taskId,$task_id)){
					$customerList[] = $v;
				}
			}
			
			if($customerList){
				$t_data['customerList'] = array_merge($c_data,$customerList);
			}else{
				$t_data['customerList'] = $c_data;
			}
			
			$arr = array();
			foreach($t_data['customerList'] as $keyt => $tv){
				if(!array_key_exists($tv->clientCode,$arr)){
					$arr[$tv->clientCode] = $keyt;
				}else{
					unset($t_data['customerList'][$arr[$tv->clientCode]]);
				}
			}
			
			$cus_arr = array();
			foreach($t_data['customerList'] as $v){
				$cus_arr[] = $v;
			}
			$t_data['customerList']= $cus_arr;
			$t_data = urlencode(json_encode($t_data));
			
			//提交任务
			//$t_url = $this->apcdservice.'submitPlan.do?json='.$t_data;
			//$result = $this->get_data($t_url);
			//$result = json_decode($result);
			
			$post_data = array('json'=>$t_data);
			
			//初始化
			$ch = curl_init();
			//设置选项，包括URL
			curl_setopt($ch, CURLOPT_URL,$this->apcdservice.'submitPlan.do');
			curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
			curl_setopt($ch, CURLOPT_HEADER, 0);
			// post数据
			curl_setopt($ch, CURLOPT_POST, 1);
			// post的变量
			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
			//执行并获取HTML文档内容
			$result = curl_exec($ch);
			//释放curl句柄
			curl_close($ch);
			//打印获得的数据
			$result = json_decode($result);
			
			/*************任务提交结束开始审核**************/		
			//所需数据
			$startDate = date('Y-m-d',time()-3600*24*7);	//查询任务开始日期
			$endDate = date('Y-m-d',time()+3600*24*7);		//查询任务结束日期
			$s_userId = $appPerson;							//审核人信息
			
			//获取审核任务列表
			$rw_uel = $this->apcdservice.'queryPlanList.do?json={"gridCodes":"","startDate":"'.$startDate.'","planType":"B","page":1,"userId":"'.$s_userId.'","pageSize":20,"doFlag":"sh","endDate":"'.$endDate.'"}';
			$rw_data = $this->get_data($rw_uel);
			$rw_data = json_decode($rw_data)->results;
			
			//待审核数据审核通过
			foreach($rw_data as $v){
				if($v->statusValue == '待审核'){
					$planId = $v->planId;
					//审核通过
					$sh_res = $this->apcdservice.'approvePlan.do?json={"doFlag":"1","planType":"B","planId":"'.$planId.'","appOption":"同意","userId":"'.$s_userId.'"}';
					$sh_data = $this->get_data($sh_res);
					$sh_data = json_decode($sh_data);
					//发送短信
					//$this->up_data->msg_send($userid);
				}
			}
			
		}
		//a($sh_data);exit;
		
	}
	
	//apcd查询任务池任务提交并审核通过
	public function task_pool_info($userid){
		/****************查询任务池任务***************/
		//查询用户网格
		$startDate = date('Y-m-d');
		$endDate = date('Y-m-d',time()+24*3600*7);
		
		$planType = 'B';		//计划类型
		$planId = '';			//计划id
		$executors = '';		//执行人id串	
		$executorNames = '';	//执行人名字
		
		$grid_url = $this->apcdservice.'queryGridList.do?json={"userId":"'.$userid.'"}'; 
		$grid = $this->get_data($grid_url);
		$grid = json_decode($grid);
		
		//拼接查询网格
		$grids = '';
		foreach($grid->results as $v){
			$grids .= $v->tagId.',';
		}
		$grids = substr($grids,0,strlen($grids)-1);
		
		//获取任务池任务
		$pool_url = $this->apcdservice.'queryTaskPoolCustomers.do?json={"gridCodes":"'.$grids.'","startDate":"'.$startDate.'","page":1,"isHaveLicense":"","taskSource":"","pageSize":20,"endDate":"'.$endDate.'","keyWord":""}';
		$task_pool = $this->get_data($pool_url);
		$task_pool = json_decode($task_pool);
		$task_pool = $task_pool->results;
		
		foreach($task_pool as $k => $v){
			$task_pool[$k]->flag = 1;
			$task_pool[$k]->checked = 'true';
			
		}
		//任务商户
		$t_data['customerList'] = $task_pool;
		
		//审核人信息
		$s_url = $this->apcdservice.'queryApprovalList.do?json={"userId":"'.$userid.'"}';
		$audit = $this->get_data($s_url);
		$audit = json_decode($audit)->results;
		$appPerson = $audit[0]->approvalId;		//appPerson
		
		//执行人信息
		$zurl = $this->apcdservice.'queryExecutorList.do?json={"userId":"'.$userid.'"}';
		$zuser = $this->get_data($zurl);
		$zuser = json_decode($zuser)->results;
		foreach($zuser as $v){
			$executors .= $v->tagId.',';
			$executorNames .= $v->tagName.',';
		}
		$executors = substr($executors,0,strlen($executors)-1);					//执行人id列表
		$executorNames = substr($executorNames,0,strlen($executorNames)-1);		//执行人姓名列表
		
		$t_data['executorNames'] = $executorNames;
		$t_data['executors'] = $executors;
		$t_data['appPerson'] = $appPerson;
		$t_data['planType'] = $planType;
		$t_data['planId'] = $planId;
		$t_data['userId'] = $userid;
		$t_data['startDate'] = $startDate;
		$t_data['endDate'] = $startDate;
		$t_data = json_encode($t_data);
		
		//提交任务
		//$t_url = 'http://218.28.88.82/apcdservice/submitPlan.do?json='.$t_data;
		//$result = $this->get_data($t_url);
		
		/*************提交完成开始审核通过**********/
		$s_userId = $appPerson;							//审核人信息
		
		//获取审核任务列表
		$rw_uel = $this->apcdservice.'queryPlanList.do?json={"gridCodes":"","startDate":"'.$startDate.'","planType":"B","page":1,"userId":"'.$s_userId.'","pageSize":20,"doFlag":"sh","endDate":"'.$endDate.'"}';
		$rw_data = $this->get_data($rw_uel);
		$rw_data = json_decode($rw_data)->results;
		
		//待审核数据审核通过
		foreach($rw_data as $v){
			if($v->statusValue == '待审核'){
				$planId = $v->planId;
				//审核通过
				$sh_res = $this->apcdservice.'approvePlan.do?json={"doFlag":"1","planType":"B","planId":"'.$planId.'","appOption":"同意","userId":"'.$s_userId.'"}';
				$sh_data = $this->get_data($sh_res);
				$sh_data = json_decode($sh_data);
			}
		}
		
	}
	

	//获取xcyc任务
	public function task_info_xcyc(){
		$planid = isset($_GET['planid'])?$_GET['planid']:'';		//计划id
		$squadron = isset($_GET['squadron'])?$_GET['squadron']:'';	//中队id
		
		$task_info = $this->up_data->task_info_xcyc($planid,$squadron);
		$task_info = json_encode($task_info);

		//$this->up_data_j($task_info);
		$this->get_visit_customer($task_info);
	}
	
	//获取apcd任务池商户
	public function get_customer(){
		
		for($i=1;$i<100000000;$i++){
			$url = $this->apcdservice.'queryCustomers.do?json={"pageSize":20,"page":10,"keyword":""}';
			
			$customer = $this->get_data($url);
			$customer = json_decode($customer);
			a($customer->msg);exit;
			if(isset($customer->results)){
				$this->up_data->get_customer($customer);
			}else{
				echo('完成..................<br />');
				ob_flush();
				flush();
				exit;
			}
		}
		
	}
	
	//同步aocd客户端用户信息
	public function apcd_user_update(){
		$xcyc_user_id = isset($_GET['xcyc_user_id'])?$_GET['xcyc_user_id']:'';
		
		if(!$xcyc_user_id){
			echo json_encode(array('status'=>'false','msg'=>'用户id不能为空'));
		}else{
			$where = " and xcyc_user_id = '$xcyc_user_id'";
			$user_info = $this->up_data->find_apcd_all_user($where);
			$password = $user_info[0]->password;
			$username = $user_info[0]->userName;
			/* $password = 'sty123';
			$username = 'xc_songjh'; */

			$apcd_user_url = $this->apcdservice.'login.do?json={"password":"'.$password.'","username":"'.$username.'"}';
			//echo $apcd_user_url;exit;
			$data = $this->get_data($apcd_user_url);
			$data = json_decode($data);
			
			//更新apcd用户信息
			if(!empty($data->data)){
				$res = $this->up_data->updata_apcd_userinfo($data->data,$xcyc_user_id);
			}
			echo json_encode(array('status'=>'true','msg'=>'成功'));
			
		}
		
		
		
	}
	
	//获取无证商户
	public function find_without_license(){
		$user_info = $this->up_data->find_apcd_all_user();
		$startDate = date('Y-m-d',time()-3600*24*7*4);
		$endDate = date('Y-m-d');
		
		foreach($user_info as $v){
			$userId = $v->apcd_app_userid;
			$url = 'http://218.28.143.166:82/apcdservice/queryInfo.do?{"id":"3001","gridCodes":"","startDate":"'.$startDate.'","endDate":"'.$endDate.'","equiptype":"android","page":"1","userId":"'.$userId.'"}';
			$without_license = $this->get_data($url);
			a($without_license);
		}
		
	}
	

	//更新商户数据
	public function excel_data(){
		header("Content-Type: text/html; charset=utf-8");
		set_time_limit(0);
		
		require_once '../../../lib/PHPExcel/PHPExcel.class.php';   
		require_once '../../../lib/PHPExcel/PHPExcel/IOFactory.php';   
		require_once '../../../lib/PHPExcel/PHPExcel/Reader/Excel2007.php';//excel 2007  
		parent::__construct();
		
		if (!empty ( $_FILES ['file_stu'] ['name'] )){
			if(!isset($_POST['ismy'])){
				echo( '请选择是否自选导入文件类型');
				ob_flush();
				flush();
				sleep(3);
				echo '<script>window.location = "up_data-data_index";</script>';
				exit;
			}else{
				$ismy = $_POST['ismy'];
			}
			
			
			$tmp_file = $_FILES ['file_stu'] ['tmp_name'];
			$file_types = explode ( ".", $_FILES ['file_stu'] ['name'] );
			$file_type = $file_types [count ( $file_types ) - 1];
			
			/*判别是不是.xls文件，判别是不是excel文件*/
			if (strtolower ( $file_type ) != "xls" && strtolower ( $file_type ) != "xlsx"){
				echo( '不是Excel文件，3秒后请重新上传');
				ob_flush();
				flush();
				sleep(3);
				echo '<script>window.location = "up_data-data_index";</script>';
				exit;
			}
			
			/*设置上传路径*/
			$savePath = '../../../theme/Excel/';
			
			/*以时间来命名上传的文件*/
			$str = date ( 'Ymdhis' ); 
			$file_name = $str . "." . $file_type;
			
			/*是否上传成功*/
			if (! copy ( $tmp_file, $savePath . $file_name )){
				echo( '上传失败' );
				ob_flush();
				flush();
				sleep(3);
				echo '<script>window.location = "up_data-data_index";</script>';
				exit;
			}else{
				echo( '上传成功，开始导入数据......<br />');
				ob_flush();
				flush();
			}
			$filename = $savePath.$file_name;
			
			$objReader = PHPExcel_IOFactory::createReader('Excel5');
			$objReader->setReadDataOnly(true);
			$objPHPExcel = $objReader->load($filename);
			$objWorksheet = $objPHPExcel->getActiveSheet(1);
			$highestRow = $objWorksheet->getHighestRow(); 
			$highestColumn = $objWorksheet->getHighestColumn(); 
			$highestColumnIndex = PHPExcel_Cell::columnIndexFromString($highestColumn); 
			
			$datas = array();
			//开始数去数据
			for($row = 1;$row<=$highestRow;$row++){
				$res = $this->read($objWorksheet,$highestRow,$highestColumnIndex,$row );
				echo date('H:i:s').$res[2].'......更新中.......<br />' ;
				ob_flush();
				flush(); 
				
				if($res){
					if($ismy == 1){
						$this->up_data->update_customer_info($res);
					}
				}else{
					exit;
				}
			}
			
			echo('导入完成....<br />' );
			ob_flush();
			flush();
			exit;
		}else{
			$this->display();
		}
		
	}
	
	
	
		/**
	* 读取excel $filename 路径文件名 $row 0 获取所有数据 否则获取对应行数据 $encode 返回数据的编码 默认为utf8
	*以下基本都不要修改
	*/
	public function read($objWorksheet,$highestRow,$highestColumnIndex,$row,$encode='utf-8'){
		
		if($row > $highestRow){
			return false;
		}
		
		$excelData = array(); 
		if($row == 0){
			for ($row = 1; $row <= $highestRow; $row++) {
				for ($col = 0; $col < $highestColumnIndex; $col++) {
					$excelData[$row][] =(string)$objWorksheet->getCellByColumnAndRow($col, $row)->getCalculatedValue();
				}
			} 
		}else{
			for ($col = 0; $col < $highestColumnIndex; $col++) {
				$excelData[] =(string)$objWorksheet->getCellByColumnAndRow($col, $row)->getCalculatedValue();
			}
		}
		
		return $excelData;
	}
	
	//get获取数据
	public function get_data($url){
		//初始化
		$ch = curl_init();
		//设置选项，包括URL
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_HEADER, 0);
		//执行并获取HTML文档内容
		$output = curl_exec($ch);
		//释放curl句柄
		curl_close($ch);
		return $output;
	}
	
	
	/**********************案件当事人身份证号抓取*****************/
	//电子卷宗查询	http://localhost/get_data/pds/up_data-caseinfo_customer
	public function caseinfo_customer(){
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$this->up_data->push_div_content('.scorpall','开始同步案件数据.............................................<br />');
		//案件列表
		$post_data = array(
			'tCCaseinfoSon.orgShortname'=>'平顶山市烟草专卖局',
			'_search'=>false,
			'nd'=>'1592826935517',
			'pageSize'=>100,
			'pageNo'=> 1,
			'orderFields'=>'caseCode',
			'order'=>'desc'
		);
		
		$dataurl = $this->regieapp_case.'tCCaseinfo/listAdministrativePenaltyFile';
		$result = $this->postcurl($dataurl,$post_data,$cookie_file);
		//a($result);exit;
		$result = json_decode($result);
		$pageTotal = $result->total; //总页数
		$recordTotal = $result->records; //总记录数
		//$result = $result->rows;
		for($p = 100; $p <= $pageTotal;$p++ ){
			$this->up_data->push_div_content('.scorpall','》》》》》》》》》》》》》'.$p.'》》》》》》》》》》》》》》<br />');
			$params = array(
				'tCCaseinfoSon.orgShortname'=>'平顶山市烟草专卖局',
				'_search'=>false,
				'nd'=>'1592826935517',
				'pageSize'=>100,
				'pageNo'=> $p,
				'orderFields'=>'caseCode',
				'order'=>'desc'
			);
			$res = $this->postcurl($dataurl,$params,$cookie_file);
			$res = json_decode($res);
			$res = $res->rows;
			if($res){
				
				foreach($res as $k => $v){
					
					$this->up_data->push_div_content('.scorpall',$v->fullDocNo.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
					//$v->regieLic = '';
					$caseUuid = $v->caseUuid;
					
					//文书列表
					$doc_post = array();
					$doc_post['caseUuid'] = $caseUuid;
					$doc_post['type'] = '1';
					
					$perm_doc = http_build_query($doc_post);
					$doc_url = $this->regieapp_case.'casequery/getCaseDetail?'.$perm_doc;
					//$doc_url = $this->regieapp_case.'fileDir/findDocFileDirListInDzjz';
					$doc_res = $this->postcurl($doc_url,$doc_post,$cookie_file);
					$doc_data = json_decode($doc_res)->rows;	//文书列表数据
					//a($doc_data);exit;
					if($doc_data){
						$rec_post = array();
						$rec_post['caseUuid'] = $caseUuid;
						$rec_post['isedit'] = 0;
						$rec_post['docType'] = '';
						//$rec_post['docUrl'] = '/tcdoclocalepunish/goLocalePunishHAN';
						$rec_post['docUrl'] = '/tCDocPunishDecide/punishHAN';
						$rec_post['isHaveX'] = 2;
						$rec_post['caseDocClick'] = true;
						
						foreach($doc_data as $docv){
							if($docv->bdtName == '行政处罚决定书'){
								$rec_post['liddId'] = $docv->licItemDocDetails->liddId;
							}
						}
						
					}
					
					//获取证件号码
					$details_url = $this->regieapp_case.'tCDocPunishDecide/punishHAN';
					//$details_url = $this->regieapp_case.'tcdoclocalepunish/goLocalePunishHAN';
					$corddes = $this->postcurl($details_url,$rec_post,$cookie_file);
					
					if(strpos($corddes,'idCard')){	//身份证号获取
						//$v->cardnum = $this->get_input_value($corddes,'idCard');
						$v->cardnum = $this->get_case_input_value($corddes,'idCard');
						$v->license = $this->up_data->getLicenseByIdcard($v->cardnum);	
					}
					//a($v);exit;
					$this->up_data->updata_caseinfo($v);
				}
				
			}
			
		}
		
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
		
	}
	
	//再办查询
	public function caseinfob(){
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$this->up_data->push_div_content('.scorpall','开始同步在办案件数据.............................................<br />');
		//案件列表
		$post_data = array(
			'tCCaseinfoSon.orgShortname'=>'南阳市烟草专卖局',
			'_search'=>'false',
			'nd'=>'1589020967808',
			'pageSize'=>10000,
			'pageNo'=> 1,
			'regStartTime'=>'2020-04-01',
			'regEndTime'=>'2020-04-30',
			'orderFields'=>'caseDate',
			'seqCode'=>'014123',
			'caseState'=>'0',
			'order'=>'desc'
		);
		
		
		$dataurl = $this->regieapp_case.'casequery/caseInfoList?handleStatus=1&unitCode=014123&orgRank=3';
		$result = $this->postcurl($dataurl,$post_data,$cookie_file);

		
		$result = json_decode($result);
		a($result);exit;
		$result = $result->rows;
		if($result){
			foreach($result as $k => $v){
				$this->up_data->push_div_content('.scorpall',$v->caseCode.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
				$v->regieLic = '';
				$caseUuid = $v->caseUuid;
				
				//文书列表
				$doc_post = array();
				$doc_post['caseUuid'] = $caseUuid;
				$doc_post['type'] = '1';
				
				$perm_doc = http_build_query($doc_post);
				$doc_url = $this->regieapp_case.'casequery/getCaseDetail?'.$perm_doc;
				
				$doc_res = $this->postcurl($doc_url,$doc_post,$cookie_file);
				$doc_data = json_decode($doc_res)->rows;	//文书列表数据
				
				if($doc_data){
					$rec_post = array();
					$rec_post['caseUuid'] = $caseUuid;
					$rec_post['isedit'] = 0;
					$rec_post['docType'] = '';
					$rec_post['docUrl'] = '/tcdoclocalepunish/goLocalePunishHAN';
					$rec_post['isHaveX'] = 2;
					$rec_post['caseDocClick'] = true;
					
					foreach($doc_data as $docv){
						if($docv->bdtName == '当场行政处罚决定书'){
							$rec_post['liddId'] = $docv->licItemDocDetails->liddId;
						}
					}
					
				}
				
				//获取证件号码
				$details_url = $this->regieapp_case.'tcdoclocalepunish/goLocalePunishHAN';
				$corddes = $this->postcurl($details_url,$rec_post,$cookie_file);
				
				if(strpos($corddes,'regieLic')){	//受理时间
					$v->cardnum = $this->get_input_value($corddes,'regieLic');	
				}
				
				$v->closeDate = '';
				$v->regDate = '';
				
				$this->up_data->updata_caseinfo_zb($v);
				//a($v);exit;
			}
			
			
		}
		
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
		
		
	}
	
	//获取案件物品
	public function getcasegoods(){
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$caseinfo = $this->up_data->get_caseinfo();
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$this->up_data->push_div_content('.scorpall','开始同步案件物品.............................................<br />');
		
		foreach($caseinfo as $v){
			$this->up_data->push_div_content('.scorpall',$v->id.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
			
			$rec_post = array();
			$caseUuid = $v->id;
			//$caseUuid = '8a83c19071c90b8e0171e259d48d5cc5';
			$url = $this->regieapp_case.'casequery/getCaseDetail?type=4&caseUuid='.$caseUuid;
			
			$corddes = $this->postcurl($url,$rec_post,$cookie_file);
			$corddes = json_decode($corddes)->rows;	//文书列表数据
			foreach($corddes as $gv){
				$this->up_data->push_div_content('.scorpall',$gv->goodsName.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
				$this->up_data->updata_case_goods($gv);
			}
			
		}
		
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
		
	}
	
	//获取卷烟32位码
	public function get_goods_code(){
		
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$goods = $this->up_data->get_casegoods();
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		
		$this->up_data->push_div_content('.scorpall','开始同步案件物品.............................................<br />');
		
		foreach($goods as $v){
			$this->up_data->push_div_content('.scorpall',$v->id.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
			
			$post = array();
			$post['goodsDtlUuid'] = $v->id;
			//$post['goodsDtlUuid'] = '8a83c19071336e2c0171338d78df0320';
			//$post['prodUuid'] = '008415';
			$post['queryMe'] = false;
			$post['_search'] = false;
			$post['nd'] = '1589094036141';
			$post['pageSize'] = 100000;
			$post['pageNo'] = 1;
			$post['orderFields'] = 'bitcodeSerialNumber';
			$post['order'] = 'asc';
			$post['isEdit'] = true;
			
			$caseUuid = $v->id;
			
			//$caseUuid = '8a83c19071c90b8e0171e259d48d5cc5';
			$url = $this->regieapp_case.'tCCiga32bitCode/list';
			
			$corddes = $this->postcurl($url,$post,$cookie_file);
			$corddes = json_decode($corddes)->rows;	//文书列表数据
			//a($corddes);exit;
			foreach($corddes as $gv){
				$this->up_data->push_div_content('.scorpall',$gv->af16bitcode.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
				$this->up_data->updata_goods_code($gv);
			}
			
		}
		
		echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
	}
	
	public function get_case_input_value($data,$name){
		
		///[\s*?]name[\s*?]=[\s*?]"idCard".*[\s*?]value[\s*?]=[\s*?][\'\"](.*)[\'\"]/isU
		preg_match_all('/[\s*?]name[\s*?]=[\s*?]"'.$name.'".*[\s*?]value[\s*?]=[\s*?][\'\"](.*)[\'\"]/isU',$data,$val);
		return  @$val[1][0];
	}
	
	//获取input的value值
	public function get_input_value($data,$name){
		
		preg_match_all('/name="'.$name.'".*value=[\'\"](.*)[\'\"]/isU',$data,$val);
		return  @$val[1][0];
	}
	
	public function postcurl($url,$data,$cookie_file){
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_URL,$url);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch, CURLOPT_POST,1);
		curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
		curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
		//curl_setopt($ch, CURLOPT_COOKIE,$cookie);
		$result = curl_exec($ch);
		curl_close($ch);
		
		return $result;
	}
	
		/*
	 *抓取市场检查记录数据
	 *王二凯
	 *2020-05-09 19:27
	 */
	 public function marketRecord(){
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		$this->up_data->push_div_content('.scorpall','开始同步案件数据.............................................<br />');
		
		
		for($p = 1;$p<= 100;$p++){
			
			//查询商户列表
			$post_data = array(
			 'rows'=>50,
			 'page'=> $p,
			 'orderFields'=>'caseCode',
			 'benCheckDate'=>'2020-04-01',
			 'endCheckDate'=>'2020-04-30',
			 'orgCode'=>'10411301',
			);
			
			$dataurl = $this->apcd.'other/stayTime_queryListSign.do';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			$customerlist = curl_exec($ch);
			curl_close($ch);
			$customerlist = json_decode($customerlist);
			$customerlist = $customerlist->rows;
			
			if($customerlist){
				foreach($customerlist as $v){
					$this->up_data->push_div_content('.scorpall',$v->SHOP_NAME.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
					
					$this->up_data->marketRecord($v);
				}
			}
		}
		

	 
		
		
	   
	   echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
	  }
	
		/*
	 *电子卷宗证件状态
	 *王二凯
	 *2020-05-09 19:27
	 */
	 public function certStatus(){
		//滚动条设置始终在最低端
		echo '<script src="http://libs.baidu.com/jquery/1.9.1/jquery.min.js"></script>';
		echo '<div class="scorpall" style="margin-bottom:60px;">';
		echo '</div>';
		
		$cookie_file = dirname(__FILE__).'/cookie.txt';
		$this->up_data->push_div_content('.scorpall','开始同步电子卷宗数据.............................................<br />');
		
		
		for($p = 2;$p<= 5;$p++){
			
			//查询商户列表
			$post_data = array(
			 'orgCode_val'=>'10411301',
			 'excelPageSize'=>'65530',
			 '_search'=>'false',
			 'nd'=>'1589073218918',
			 'pageNo'=>$p,
			 'pageSize'=>'1000',
			 'bookbuildStartTime'=>'2020-04-01',
			 'bookbuildEndTime'=>'2020-04-30',
			 'unitCode'=>'014123',
			 'orderFields'=>'auditUnits,fileCode',
			 'order'=>'asc,desc',
			);

			$dataurl = $this->regieapp_lic.'electronfile/getEleFileList';
			$ch = curl_init();
			curl_setopt($ch, CURLOPT_URL,$dataurl);
			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
			curl_setopt($ch, CURLOPT_POST,1);
			curl_setopt($ch, CURLOPT_POSTFIELDS,$post_data);
			curl_setopt($ch, CURLOPT_COOKIEFILE,$cookie_file);
			$customerlist = curl_exec($ch);
			curl_close($ch);
			$customerlist = json_decode($customerlist);
			$customerlist = $customerlist->rows;
			
			if($customerlist){
				foreach($customerlist as $v){
					//a($v);exit;
					$this->up_data->push_div_content('.scorpall',$v->companyWordSizeName.'》》》》》》》》》》》》》》》》》》》》》》》》》》》<br />');
					
					$this->up_data->certStatus($v);
				}
			}
		}
		

	 
		
		
	   
	   echo '<span style="color:red;font-size:26px;"> 同步完成</span>';
	  }
	
	
	
	
	
	
	
	
	
	
	
	
}
?>